Page 1 of 11

 

  Table Of ContentsNext Page
Table of Contents

 Introduction
• Starting point
• Major FP design patterns/functions in XSLT
• List processing
• Tree processing
• Lazy evaluation
• Advanced XSLT FP applications
• Square root
• Numerical differentiation
• Numerical integration
• Summary


The Functional Programming Language XSLT - A proof through examples

Dimitre Novatchev (dnovatchev@yahoo.com)
November, 2001

Until now it was believed that although XSLT is based on functional programming ideas, it is not as yet a full functional programming language, as it lacks the ability to treat functions as a first-class data type. Based on numerous concrete XSLT implementations of some of the major functional programming design patterns, including some of the most generic list-processing and tree-processing functions, this article provides ample proof that XSLT is in fact a full-pledged functional programming language. The presented code forms the base of a first XSLT functional programming library. It is emphasized that a decision to include higher-order functions support in XPath 2.0 will make functional programming in XSLT even more straightforward, natural and convenient.

The source code for this article is part of the FXSL library version 1.1 and can be downloaded here:

  Using MSXML?  Get the MSXML source code!

  Using SAXON?  Get the SAXON source code!

  Using XALAN?  Get the XALAN source code as adapted by Knut Wannheden !

Introduction

XSLT has turned out to be very different from the typical programming languages in use today. One question that's being asked frequently is: "What kind of programming language is actually XSLT?". Until now, the authoritative answer from some of the best specialists was that XSLT is a declarative (as opposed to imperative) but still not a functional programming (FP) language. Michael Kay notes in his article "What kind of language is XSLT" [3] :
"although XSLT is based on functional programming ideas, it is not as yet a full functional programming language, as it lacks the ability to treat functions as a first-class data type".

What has been done to bring XML and FP languages closer together? One notable direction is to add XML support to some well-known FP languages, such as the HaXML compiler and tools written in Haskell [6], the LambdaXML xml-based FP  language and the XML support in Erlang [2].

However, nothing is seemingly being done in the other direction -- to add functional programming capabilities to XSLT. The citation in the start of this section reflects the unanimous, dominating understanding of XSLT as a declarative-only programming language, which does not belong to the family of FP languages, due to its lack of support for higher order functions.

The purpose of this article is to demonstrate beyond any doubt that XSLT is a functional programming language in its own right. To achieve this goal, a reference XSLT implementation is provided of major FP concepts and functions. This article closely follows the contents and layout of John Hughes' article "Why functional programming matters" [1], in which some most typical and useful FP patterns and functions are defined. This article provides an XSLT implementation of most of the functions defined in [1].  Therefore, the reader is encouraged to read [1] either prior, or side-by-side with the current article.

 

Page 1 of 11

 

  Table Of ContentsNext Page

SourceForge.net Logo